package com.example.chartbar;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.example.chartbar.util.DateUtil;
import com.example.chartbar.util.MPChartHelper;
import com.example.chartbar.view.CountLineChart;
import com.github.mikephil.charting.charts.LineChart;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private LineChart lineChart;
    private CountLineChart lineChart2;
    private List<String> xAxisValues;
    private List<Float> yAxisValues;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initData();
    }

    private void initView() {
        lineChart = findViewById(R.id.line_chart);
        lineChart2 = findViewById(R.id.line_chart2);
    }

    private void initData() {
        xAxisValues = new ArrayList<>();
        yAxisValues = new ArrayList<>();

        for (int i = 0; i < 30; ++i) {
            String   monthFromDate = DateUtil.getMonthFromDate(DateUtil.getDate(i));
            String dayFromDate = DateUtil.getDayFromDate(DateUtil.getDate(i));
            String foremat = "";
            if (i == 0) {

                foremat = String.format(getResources().getString(R.string.calendar_detail_month_day), monthFromDate, dayFromDate);
                xAxisValues.add(foremat);
            } else {
                 foremat = String.format(getResources().getString(R.string.calendar_detail_day), dayFromDate);
                xAxisValues.add(foremat);
            }

            yAxisValues.add((float) (Math.random() * 65));
        }

        MPChartHelper.setLineChart(lineChart, xAxisValues, yAxisValues, "", this);
        MPChartHelper.setLineChart(lineChart2, xAxisValues, yAxisValues, "",  this);
    }
}
